﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 玩具商城管理系统.znew
{
    public partial class dg : Form
    {
        public dg()
        {
            InitializeComponent();
        }
        Class1 shopcarSrv = new Class1();
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
                MessageBox.Show("您的订购订单已提交给店铺，审核通过后即可付款");
           
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            
        }
        public static decimal profit = 0;
        SqlDataAdapter dashopcar, daProduct;
        DataSet ds = new DataSet();
        void init()
        {
            string str = "select shopcar_id,shopcar_commodityid,shopcar_clientid,shopcar_commodityname,shopcar_money,shopcar_num from shopcar where shopcar_clientid='" + login.username + "'";
            dashopcar = new SqlDataAdapter(str, DB.cn);
            dashopcar.Fill(ds, "shopcar_info");
            string sdr = "select * from commodity";
            daProduct = new SqlDataAdapter(sdr, DB.cn);
            daProduct.Fill(ds, "product_info");
        }
        void UpdateDB()
        {
            try
            {
                SqlCommandBuilder dbshopcar = new SqlCommandBuilder(dashopcar);
                dashopcar.Update(ds, "shopcar_info");
                SqlCommandBuilder dbProduct = new SqlCommandBuilder(daProduct);
                daProduct.Update(ds, "product_info");
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        void Bind()
        {
            init();
            DB.GetCn();
            string sdr = "select client_power from client where client_name='" + login.username + "'";
            SqlCommand command = new SqlCommand(sdr, DB.cn);

            label9.Text = shopcarSrv.GetTotalPriceByshopcar_clientid(login.username).Item1.ToString();
            DataView dvCartItem = new DataView(ds.Tables["shopcar_info"]);
            dgvProduct.DataSource = dvCartItem;

        }
        private void dg_Load(object sender, EventArgs e)
        {
            Bind();

            // TODO: 这行代码将数据加载到表“toyStroeDataSet.shopcar”中。您可以根据需要移动或移除它。
            this.shopcarTableAdapter.Fill(this.toyStroeDataSet.shopcar);
            DB.GetCn();
            List<int> List_index = new List<int>();
            if (dgvProduct.Rows.Count > 0)
            {
                for (int i = 0; i < dgvProduct.Rows.Count - 1; i++)
                {
                    List_index.Add(i);

                }
                int z = 0;
                foreach (int n in List_index)
                {
                    dgvProduct.Rows.RemoveAt(n - z);
                    z++;
                }
                UpdateDB();
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            
        }
    }
}
